/*
	This file is part of AVRCppLib.

    AVRCppLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AVRCppLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AVRCppLib.  If not, see <http://www.gnu.org/licenses/>.

    Copyright (C) Maxime Lemonnier 2007-2011
 */

#ifndef I2CMaster_H_
#define I2CMaster_H_

#include "I2CHardware.h"
#include "../../DataStructures/ActiveBuffers/ActiveReceiveBuffers/ActiveReceiveBuffer.h"
#include "../../DataStructures/ActiveBuffers/ActiveReceiveBuffers/ActiveReceiveBufferObserver.h"
#include "../../DataStructures/ActiveBuffers/ActiveTransmitBuffers/ActiveTransmitBuffer.h"
#include "../../DataStructures/ActiveBuffers/ActiveTransmitBuffers/ActiveTransmitBufferObserver.h"

namespace Coms
{

namespace I2C
{

class I2CMaster
{
public:
	I2CMaster(I2CHardware * i2cHardware);
	virtual ~I2CMaster();

	void setDestinationAddress(uint8_t destinationAddress);

	uint8_t readRegister(uint8_t registerAddress);
	void writeRegister(uint8_t registerAddress, uint8_t registerContent);

	void readRegisters(uint8_t startRegisterAddress, ActiveReceiveBuffer * receiveBuffer);
	void writeRegisters(uint8_t startRegisterAddress, ActiveTransmitBuffer * transmitBuffer);

	void writeRegistersAM(uint8_t registerAddress, uint8_t *RegisterBuf, uint32_t BufSizeByte);

protected:
	bool selectRegister(uint8_t registerAddress);

protected:

	I2CHardware * i2cHardware;

	uint8_t destinationAddress;
};

}

}

#endif /* I2CMaster_H_ */
